//
//  ByMyDocumentaryListCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/22.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByMyDocumentaryListCell.h"

@implementation ByMyDocumentaryListCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByMyDocumentaryListCell";
    ByMyDocumentaryListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        [self initViews];
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [backgroundView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(11);
        make.top.equalTo(backgroundView).offset(14);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [backgroundView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-35);
        make.top.equalTo(iconView.mas_top).offset(10);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@100);
    }];
    moneyLabel.text = @"投注100元";
    moneyLabel.font = FONT(12);
    moneyLabel.textColor = [UIColor blackColor];
    moneyLabel.textAlignment = NSTextAlignmentRight;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(10);
        make.centerY.equalTo(iconView.mas_centerY).offset(0);
        make.height.mas_equalTo(@20);
        make.right.equalTo(moneyLabel.mas_left).offset(-10);
    }];
    titleLabel.text = @"未中奖";
    titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:15];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    [backgroundView addSubview:arrowView];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-10);
        make.centerY.equalTo(iconView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    arrowView.image = [UIImage imageNamed:@"youjiantou1111"];
    
    
    UILabel *timeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(moneyLabel.mas_left).offset(0);
        make.top.equalTo(moneyLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(@15);
        make.right.equalTo(moneyLabel.mas_right).offset(0);
    }];
    timeLabel.font = FONT(14);
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.textAlignment = NSTextAlignmentRight;
    
    self.iconView = iconView;
    self.moneyLabel = moneyLabel;
    self.titleLabel = titleLabel;
    self.timeLabel = timeLabel;
    
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(iconView.mas_bottom).offset(12);
        make.height.mas_equalTo(@1);
    }];
    
    UILabel *endTimeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:endTimeLabel];
    [endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.bottom.equalTo(backgroundView).offset(-17);
        make.height.mas_equalTo(@15);
        make.right.equalTo(backgroundView).offset(-100);
    }];
    endTimeLabel.font = FONT(14);
    endTimeLabel.textColor = [UIColor lightGrayColor];
    endTimeLabel.textAlignment = NSTextAlignmentLeft;
    endTimeLabel.hidden = YES;
    self.endTimeLabel = endTimeLabel;
    
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-10);
        make.bottom.equalTo(backgroundView).offset(-8);
        make.size.mas_equalTo(CGSizeMake(66, 27));
    }];
    rightBtn.backgroundColor = BY_THEME_COLOR;
    [rightBtn setTitle:@"收入详情" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.layer.cornerRadius = 9;
    rightBtn.titleLabel.font = FONT(12);
    [rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn = rightBtn;
}


- (void)rightAction:(UIButton *)btn{
    if (self.rightBlock) {
        self.rightBlock();
    }
}

- (void)setIsMyDocumentary:(BOOL)isMyDocumentary{
    _isMyDocumentary = isMyDocumentary;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:_netModel.logo] placeholderImage:DEFAULT_IMAGE];
    self.moneyLabel.text = [NSString stringWithFormat:@"投注%@元", _netModel.total_amount];
    self.timeLabel.text = [NSString stringWithFormat:@"%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.create_time.integerValue formatter:@"yyyy-MM-dd"]];
   
    if (_netModel.pay_status.integerValue == 1) {
        
        if (netModel.is_result.integerValue == 0) {
            self.titleLabel.text = @"待开奖";
            self.titleLabel.textColor = [UIColor colorWithHexString:@"#3525E6"];
        }else{
            if (netModel.lottery_result.integerValue == 0) {
                self.titleLabel.text = @"未中奖";
                self.titleLabel.textColor = [UIColor colorWithHexString:@"#15171B"];
            }else{
                self.titleLabel.text = [NSString stringWithFormat:@"已中奖%.2f元",_netModel.win_amount.floatValue];
                self.titleLabel.textColor = [UIColor colorWithHexString:@"#D91D36"];
            }
        }
        
    }else if (_netModel.pay_status.integerValue == 2){
        
         self.titleLabel.text = @"交易关闭";
    }
    
   
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970];
    [self.rightBtn setTitle:@"收入详情" forState:UIControlStateNormal];
 
    
    //未支付
    if (_netModel.pay_status.integerValue == 0) {
     [self.rightBtn setTitle:@"支付" forState:UIControlStateNormal];
     self.titleLabel.text = @"未支付";
    }
    
    
}


@end
